package com.admin.action.query_book_Info;


import com.admin.Action;
import com.admin.dto.BookListBean;
import com.admin.service.bookservice.BookServiceImpl;

import com.admin.service.bookservice.BookServiceInF;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;


/**
 * 借书界面显示所有书籍信息
 */
public class QueryAllBookInfoAction extends Action {
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        PrintWriter out=response.getWriter();
        HttpSession session = request.getSession();
        if(session.getAttribute("adminInfo")==null){
            out.println("<script>parent.window.location.href='error.html';</script>");
            return;
        }

        BookServiceImpl booksService = new BookServiceImpl();

        Gson gson = new Gson();

//        list=booksService.queryAllBookInfo();
//        System.out.println(list);
//        String jsonStr = gson.toJson(list);
//        out.print(jsonStr);

        //分页
        BookServiceInF service= new BookServiceImpl();
        int count= service.getCount();
        out.print(count);
        int index= Integer.parseInt(request.getParameter("index"));
        System.out.println("页数"+index);
        out.print(",");
        List<BookListBean>  booksBeans=service.bookList(index,4);
//        request.setAttribute();
        //发送数据条数
        System.out.println(booksBeans);
        String jsonStr =   gson.toJson(booksBeans);
        out.print(jsonStr);
//





    }
}
